<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>16多圈动画</title>
  </head>
  <body>
    <canvas id="canvas" height="500" width="500"></canvas>
    <script>
      const canvas = document.getElementById('canvas')
      const ctx = canvas.getContext('2d')

      // 业务
      var radius = 100
      var increse = true

      function draw() {
        ctx.clearRect(0, 0, canvas.width, canvas.height)
        // 绘制第一个圆
        ctx.beginPath()
        ctx.arc(102, 102, radius, 0, Math.PI * 2)
        ctx.closePath()
        ctx.fillStyle = 'green'
        ctx.fill()
        // 绘制第二个圆
        ctx.beginPath()
        ctx.arc(102, 102, 50, 0, Math.PI * 2)
        ctx.closePath()
        ctx.fillStyle = 'skyblue'
        ctx.fill()
        if (radius > 100) {
          increse = false
        } else if (radius < 50) {
          increse = true
        }
        if (increse) {
          radius++
        } else {
          radius--
        }
      }
      setInterval(draw, 20)
    </script>
  </body>
</html>
